﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RelationExpertSystem
{
    public static class ExtensionMethods
    {
        public static string GetShortName(this Type me)
        {
            string shortName = me.ToString();
            int i = shortName.LastIndexOf('.');
            shortName = shortName.Substring(i + 1);
            return shortName;
        }

        public static bool ContainsPerson(this IEnumerable<Person> me, string name)
        {
            return !Person.IsNull(me.GetElement(name));
        }

        public static Person GetElement(this IEnumerable<Person> me, string name)
        {
            foreach (Person p in me)
            {
                if (p.Name == name)
                    return p;
            }
            return null;
        }

        public static IEnumerable<T> ShallowCopy<T>(this IEnumerable<T> me)
        {
            List<T> copy = new List<T>();
            foreach (T p in me)
                copy.Add(p);

            return copy;
        }
    }
}
